home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / perl5000.zip / perl5000 / sv.h < prev    next >
C/C++ Source or Header  |  1994-10-17  |  18KB  |  539 lines

  1. /*    sv.h
  2.  *
  3.  *    Copyright (c) 1991-1994, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9.  
  10. #ifdef sv_flags
  11. #undef sv_flags        /* Convex has this in <signal.h> for sigvec() */
  12. #endif
  13.  
  14. typedef enum {
  15.     SVt_NULL,    /* 0 */
  16.     SVt_IV,        /* 1 */
  17.     SVt_NV,        /* 2 */
  18.     SVt_RV,        /* 3 */
  19.     SVt_PV,        /* 4 */
  20.     SVt_PVIV,    /* 5 */
  21.     SVt_PVNV,    /* 6 */
  22.     SVt_PVMG,    /* 7 */
  23.     SVt_PVBM,    /* 8 */
  24.     SVt_PVLV,    /* 9 */
  25.     SVt_PVAV,    /* 10 */
  26.     SVt_PVHV,    /* 11 */
  27.     SVt_PVCV,    /* 12 */
  28.     SVt_PVGV,    /* 13 */
  29.     SVt_PVFM,    /* 14 */
  30.     SVt_PVIO    /* 15 */
  31. } svtype;
  32.  
  33. /* Using C's structural equivalence to help emulate C++ inheritance here... */
  34.  
  35. struct sv {
  36.     void*    sv_any;        /* pointer to something */
  37.     U32        sv_refcnt;    /* how many references to us */
  38.     U32        sv_flags;    /* what we are */
  39. };
  40.  
  41. struct gv {
  42.     XPVGV*    sv_any;        /* pointer to something */
  43.     U32        sv_refcnt;    /* how many references to us */
  44.     U32        sv_flags;    /* what we are */
  45. };
  46.  
  47. struct cv {
  48.     XPVGV*    sv_any;        /* pointer to something */
  49.     U32        sv_refcnt;    /* how many references to us */
  50.     U32        sv_flags;    /* what we are */
  51. };
  52.  
  53. struct av {
  54.     XPVAV*    sv_any;        /* pointer to something */
  55.     U32        sv_refcnt;    /* how many references to us */
  56.     U32        sv_flags;    /* what we are */
  57. };
  58.  
  59. struct hv {
  60.     XPVHV*    sv_any;        /* pointer to something */
  61.     U32        sv_refcnt;    /* how many references to us */
  62.     U32        sv_flags;    /* what we are */
  63. };
  64.  
  65. struct io {
  66.     XPVIO*    sv_any;        /* pointer to something */
  67.     U32        sv_refcnt;    /* how many references to us */
  68.     U32        sv_flags;    /* what we are */
  69. };
  70.  
  71. #define SvANY(sv)    (sv)->sv_any
  72. #define SvFLAGS(sv)    (sv)->sv_flags
  73.  
  74. #define SvREFCNT(sv)    (sv)->sv_refcnt
  75. #ifdef CRIPPLED_CC
  76. #define SvREFCNT_inc(sv)    sv_newref((SV*)sv)
  77. #define SvREFCNT_dec(sv)    sv_free((SV*)sv)
  78. #else
  79. #define SvREFCNT_inc(sv)    ((Sv = (SV*)(sv)), \
  80.                     (Sv && ++SvREFCNT(Sv)), (SV*)Sv)
  81. #define SvREFCNT_dec(sv)    sv_free((SV*)sv)
  82. #endif
  83.  
  84. #define SVTYPEMASK    0xff
  85. #define SvTYPE(sv)    ((sv)->sv_flags & SVTYPEMASK)
  86.  
  87. #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
  88.  
  89. #define SVs_PADBUSY    0x00000100    /* reserved for tmp or my already */
  90. #define SVs_PADTMP    0x00000200    /* in use as tmp */
  91. #define SVs_PADMY    0x00000400    /* in use a "my" variable */
  92. #define SVs_TEMP    0x00000800    /* string is stealable? */
  93. #define SVs_OBJECT    0x00001000    /* is "blessed" */
  94. #define SVs_GMG        0x00002000    /* has magical get method */
  95. #define SVs_SMG        0x00004000    /* has magical set method */
  96. #define SVs_RMG        0x00008000    /* has random magical methods */
  97.  
  98. #define SVf_IOK        0x00010000    /* has valid public integer value */
  99. #define SVf_NOK        0x00020000    /* has valid public numeric value */
  100. #define SVf_POK        0x00040000    /* has valid public pointer value */
  101. #define SVf_ROK        0x00080000    /* has a valid reference pointer */
  102.  
  103. #define SVf_FAKE    0x00100000    /* glob is just a copy */
  104. #define SVf_OOK        0x00200000    /* has valid offset value */
  105. #define SVf_BREAK    0x00400000    /* refcnt is artificially low */
  106. #define SVf_READONLY    0x00800000    /* may not be modified */
  107.  
  108. #define SVf_THINKFIRST    (SVf_READONLY|SVf_ROK)
  109.  
  110. #define SVp_IOK        0x01000000    /* has valid non-public integer value */
  111. #define SVp_NOK        0x02000000    /* has valid non-public numeric value */
  112. #define SVp_POK        0x04000000    /* has valid non-public pointer value */
  113. #define SVp_SCREAM    0x08000000    /* has been studied? */
  114.  
  115. #define SVf_OK        (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
  116.              SVp_IOK|SVp_NOK|SVp_POK)
  117.  
  118. #ifdef OVERLOAD
  119. #define SVf_AMAGIC    0x10000000      /* has magical overloaded methods */
  120. #endif /* OVERLOAD */
  121.  
  122. #define PRIVSHIFT 8
  123.  
  124. /* Some private flags. */
  125.  
  126. #define SVpfm_COMPILED    0x80000000
  127.  
  128. #define SVpbm_VALID    0x80000000
  129. #define SVpbm_CASEFOLD    0x40000000
  130. #define SVpbm_TAIL    0x20000000
  131.  
  132. #define SVpgv_MULTI    0x80000000
  133.  
  134. #ifdef OVERLOAD
  135. #define SVpgv_AM        0x40000000
  136. /* #define SVpgv_badAM     0x20000000 */
  137. #endif /* OVERLOAD */
  138.  
  139. struct xrv {
  140.     SV *    xrv_rv;        /* pointer to another SV */
  141. };
  142.  
  143. struct xpv {
  144.     char *    xpv_pv;        /* pointer to malloced string */
  145.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  146.     STRLEN    xpv_len;    /* allocated size */
  147. };
  148.  
  149. struct xpviv {
  150.     char *    xpv_pv;        /* pointer to malloced string */
  151.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  152.     STRLEN    xpv_len;    /* allocated size */
  153.     IV        xiv_iv;        /* integer value or pv offset */
  154. };
  155.  
  156. struct xpvnv {
  157.     char *    xpv_pv;        /* pointer to malloced string */
  158.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  159.     STRLEN    xpv_len;    /* allocated size */
  160.     IV        xiv_iv;        /* integer value or pv offset */
  161.     double    xnv_nv;        /* numeric value, if any */
  162. };
  163.  
  164. struct xpvmg {
  165.     char *    xpv_pv;        /* pointer to malloced string */
  166.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  167.     STRLEN    xpv_len;    /* allocated size */
  168.     IV        xiv_iv;        /* integer value or pv offset */
  169.     double    xnv_nv;        /* numeric value, if any */
  170.     MAGIC*    xmg_magic;    /* linked list of magicalness */
  171.     HV*        xmg_stash;    /* class package */
  172. };
  173.  
  174. struct xpvlv {
  175.     char *    xpv_pv;        /* pointer to malloced string */
  176.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  177.     STRLEN    xpv_len;    /* allocated size */
  178.     IV        xiv_iv;        /* integer value or pv offset */
  179.     double    xnv_nv;        /* numeric value, if any */
  180.     MAGIC*    xmg_magic;    /* linked list of magicalness */
  181.     HV*        xmg_stash;    /* class package */
  182.  
  183.     STRLEN    xlv_targoff;
  184.     STRLEN    xlv_targlen;
  185.     SV*        xlv_targ;
  186.     char    xlv_type;
  187. };
  188.  
  189. struct xpvgv {
  190.     char *    xpv_pv;        /* pointer to malloced string */
  191.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  192.     STRLEN    xpv_len;    /* allocated size */
  193.     IV        xiv_iv;        /* integer value or pv offset */
  194.     double    xnv_nv;        /* numeric value, if any */
  195.     MAGIC*    xmg_magic;    /* linked list of magicalness */
  196.     HV*        xmg_stash;    /* class package */
  197.  
  198.     GP*        xgv_gp;
  199.     char*    xgv_name;
  200.     STRLEN    xgv_namelen;
  201.     HV*        xgv_stash;
  202. };
  203.  
  204. struct xpvbm {
  205.     char *    xpv_pv;        /* pointer to malloced string */
  206.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  207.     STRLEN    xpv_len;    /* allocated size */
  208.     IV        xiv_iv;        /* integer value or pv offset */
  209.     double    xnv_nv;        /* numeric value, if any */
  210.     MAGIC*    xmg_magic;    /* linked list of magicalness */
  211.     HV*        xmg_stash;    /* class package */
  212.  
  213.     I32        xbm_useful;    /* is this constant pattern being useful? */
  214.     U16        xbm_previous;    /* how many characters in string before rare? */
  215.     U8        xbm_rare;    /* rarest character in string */
  216. };
  217.  
  218. struct xpvfm {
  219.     char *    xpv_pv;        /* pointer to malloced string */
  220.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  221.     STRLEN    xpv_len;    /* allocated size */
  222.     IV        xiv_iv;        /* integer value or pv offset */
  223.     double    xnv_nv;        /* numeric value, if any */
  224.     MAGIC*    xmg_magic;    /* linked list of magicalness */
  225.     HV*        xmg_stash;    /* class package */
  226.  
  227.     HV *    xcv_stash;
  228.     OP *    xcv_start;
  229.     OP *    xcv_root;
  230.     void      (*xcv_xsub)_((CV*));
  231.     ANY        xcv_xsubany;
  232.     GV *    xcv_gv;
  233.     GV *    xcv_filegv;
  234.     long    xcv_depth;        /* >= 2 indicates recursive call */
  235.     AV *    xcv_padlist;
  236.     I32        xfm_lines;
  237. };
  238.  
  239. struct xpvio {
  240.     char *    xpv_pv;        /* pointer to malloced string */
  241.     STRLEN    xpv_cur;    /* length of xpv_pv as a C string */
  242.     STRLEN    xpv_len;    /* allocated size */
  243.     IV        xiv_iv;        /* integer value or pv offset */
  244.     double    xnv_nv;        /* numeric value, if any */
  245.     MAGIC*    xmg_magic;    /* linked list of magicalness */
  246.     HV*        xmg_stash;    /* class package */
  247.  
  248.     FILE *    xio_ifp;    /* ifp and ofp are normally the same */
  249.     FILE *    xio_ofp;    /* but sockets need separate streams */
  250.     DIR *    xio_dirp;    /* for opendir, readdir, etc */
  251.     long    xio_lines;    /* $. */
  252.     long    xio_page;    /* $% */
  253.     long    xio_page_len;    /* $= */
  254.     long    xio_lines_left;    /* $- */
  255.     char *    xio_top_name;    /* $^ */
  256.     GV *    xio_top_gv;    /* $^ */
  257.     char *    xio_fmt_name;    /* $~ */
  258.     GV *    xio_fmt_gv;    /* $~ */
  259.     char *    xio_bottom_name;/* $^B */
  260.     GV *    xio_bottom_gv;    /* $^B */
  261.     short    xio_subprocess;    /* -| or |- */
  262.     char    xio_type;
  263.     char    xio_flags;
  264. };
  265.  
  266. #define IOf_ARGV 1    /* this fp iterates over ARGV */
  267. #define IOf_START 2    /* check for null ARGV and substitute '-' */
  268. #define IOf_FLUSH 4    /* this fp wants a flush after write op */
  269.  
  270. /* The following macros define implementation-independent predicates on SVs. */
  271.  
  272. #define SvNIOK(sv)        (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
  273. #define SvNIOK_off(sv)        (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
  274.                           SVp_IOK|SVp_NOK))
  275.  
  276. #define SvOK(sv)        (SvFLAGS(sv) & SVf_OK)
  277.  
  278. #ifdef OVERLOAD
  279. #define SvOK_off(sv)        (SvFLAGS(sv) &=    ~(SVf_OK|SVf_AMAGIC),    \
  280.                             SvOOK_off(sv))
  281. #else
  282. #define SvOK_off(sv)        (SvFLAGS(sv) &=    ~SVf_OK, SvOOK_off(sv))
  283. #endif /* OVERLOAD */
  284.  
  285. #define SvOKp(sv)        (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
  286. #define SvIOKp(sv)        (SvFLAGS(sv) & SVp_IOK)
  287. #define SvIOKp_on(sv)        (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
  288. #define SvNOKp(sv)        (SvFLAGS(sv) & SVp_NOK)
  289. #define SvNOKp_on(sv)        (SvFLAGS(sv) |= SVp_NOK)
  290. #define SvPOKp(sv)        (SvFLAGS(sv) & SVp_POK)
  291. #define SvPOKp_on(sv)        (SvFLAGS(sv) |= SVp_POK)
  292.  
  293. #define SvIOK(sv)        (SvFLAGS(sv) & SVf_IOK)
  294. #define SvIOK_on(sv)        (SvOOK_off(sv), \
  295.                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
  296. #define SvIOK_off(sv)        (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
  297. #define SvIOK_only(sv)        (SvOK_off(sv), \
  298.                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
  299.  
  300. #define SvNOK(sv)        (SvFLAGS(sv) & SVf_NOK)
  301. #define SvNOK_on(sv)        (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
  302. #define SvNOK_off(sv)        (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
  303. #define SvNOK_only(sv)        (SvOK_off(sv), \
  304.                     SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
  305.  
  306. #define SvPOK(sv)        (SvFLAGS(sv) & SVf_POK)
  307. #define SvPOK_on(sv)        (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
  308. #define SvPOK_off(sv)        (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
  309. #define SvPOK_only(sv)        (SvOK_off(sv), \
  310.                     SvFLAGS(sv) |= (SVf_POK|SVp_POK))
  311.  
  312. #define SvOOK(sv)        (SvFLAGS(sv) & SVf_OOK)
  313. #define SvOOK_on(sv)        (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
  314. #define SvOOK_off(sv)        (SvOOK(sv) && sv_backoff(sv))
  315.  
  316. #define SvFAKE(sv)        (SvFLAGS(sv) & SVf_FAKE)
  317. #define SvFAKE_on(sv)        (SvFLAGS(sv) |= SVf_FAKE)
  318. #define SvFAKE_off(sv)        (SvFLAGS(sv) &= ~SVf_FAKE)
  319.  
  320. #define SvROK(sv)        (SvFLAGS(sv) & SVf_ROK)
  321. #define SvROK_on(sv)        (SvFLAGS(sv) |= SVf_ROK)
  322.  
  323. #ifdef OVERLOAD
  324. #define SvROK_off(sv)        (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
  325. #else
  326. #define SvROK_off(sv)        (SvFLAGS(sv) &= ~SVf_ROK)
  327. #endif /* OVERLOAD */
  328.  
  329. #define SvMAGICAL(sv)        (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
  330. #define SvMAGICAL_on(sv)    (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
  331. #define SvMAGICAL_off(sv)    (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
  332.  
  333. #define SvGMAGICAL(sv)        (SvFLAGS(sv) & SVs_GMG)
  334. #define SvGMAGICAL_on(sv)    (SvFLAGS(sv) |= SVs_GMG)
  335. #define SvGMAGICAL_off(sv)    (SvFLAGS(sv) &= ~SVs_GMG)
  336.  
  337. #define SvSMAGICAL(sv)        (SvFLAGS(sv) & SVs_SMG)
  338. #define SvSMAGICAL_on(sv)    (SvFLAGS(sv) |= SVs_SMG)
  339. #define SvSMAGICAL_off(sv)    (SvFLAGS(sv) &= ~SVs_SMG)
  340.  
  341. #define SvRMAGICAL(sv)        (SvFLAGS(sv) & SVs_RMG)
  342. #define SvRMAGICAL_on(sv)    (SvFLAGS(sv) |= SVs_RMG)
  343. #define SvRMAGICAL_off(sv)    (SvFLAGS(sv) &= ~SVs_RMG)
  344.  
  345. #ifdef OVERLOAD
  346. #define SvAMAGIC(sv)         (SvFLAGS(sv) & SVf_AMAGIC)
  347. #define SvAMAGIC_on(sv)      (SvFLAGS(sv) |= SVf_AMAGIC)
  348. #define SvAMAGIC_off(sv)     (SvFLAGS(sv) &= ~SVf_AMAGIC)
  349.  
  350. /*
  351. #define Gv_AMG(stash) \
  352.         (HV_AMAGICmb(stash) && \
  353.          ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
  354. */
  355. #define Gv_AMG(stash)           (amagic_generation && Gv_AMupdate(stash))
  356. #endif /* OVERLOAD */
  357.  
  358. #define SvTHINKFIRST(sv)    (SvFLAGS(sv) & SVf_THINKFIRST)
  359.  
  360. #define SvPADBUSY(sv)        (SvFLAGS(sv) & SVs_PADBUSY)
  361.  
  362. #define SvPADTMP(sv)        (SvFLAGS(sv) & SVs_PADTMP)
  363. #define SvPADTMP_on(sv)        (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
  364. #define SvPADTMP_off(sv)    (SvFLAGS(sv) &= ~SVs_PADTMP)
  365.  
  366. #define SvPADMY(sv)        (SvFLAGS(sv) & SVs_PADMY)
  367. #define SvPADMY_on(sv)        (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
  368.  
  369. #define SvTEMP(sv)        (SvFLAGS(sv) & SVs_TEMP)
  370. #define SvTEMP_on(sv)        (SvFLAGS(sv) |= SVs_TEMP)
  371. #define SvTEMP_off(sv)        (SvFLAGS(sv) &= ~SVs_TEMP)
  372.  
  373. #define SvOBJECT(sv)        (SvFLAGS(sv) & SVs_OBJECT)
  374. #define SvOBJECT_on(sv)        (SvFLAGS(sv) |= SVs_OBJECT)
  375. #define SvOBJECT_off(sv)    (SvFLAGS(sv) &= ~SVs_OBJECT)
  376.  
  377. #define SvREADONLY(sv)        (SvFLAGS(sv) & SVf_READONLY)
  378. #define SvREADONLY_on(sv)    (SvFLAGS(sv) |= SVf_READONLY)
  379. #define SvREADONLY_off(sv)    (SvFLAGS(sv) &= ~SVf_READONLY)
  380.  
  381. #define SvSCREAM(sv)        (SvFLAGS(sv) & SVp_SCREAM)
  382. #define SvSCREAM_on(sv)        (SvFLAGS(sv) |= SVp_SCREAM)
  383. #define SvSCREAM_off(sv)    (SvFLAGS(sv) &= ~SVp_SCREAM)
  384.  
  385. #define SvCOMPILED(sv)        (SvFLAGS(sv) & SVpfm_COMPILED)
  386. #define SvCOMPILED_on(sv)    (SvFLAGS(sv) |= SVpfm_COMPILED)
  387. #define SvCOMPILED_off(sv)    (SvFLAGS(sv) &= ~SVpfm_COMPILED)
  388.  
  389. #define SvTAIL(sv)        (SvFLAGS(sv) & SVpbm_TAIL)
  390. #define SvTAIL_on(sv)        (SvFLAGS(sv) |= SVpbm_TAIL)
  391. #define SvTAIL_off(sv)        (SvFLAGS(sv) &= ~SVpbm_TAIL)
  392.  
  393. #define SvCASEFOLD(sv)        (SvFLAGS(sv) & SVpbm_CASEFOLD)
  394. #define SvCASEFOLD_on(sv)    (SvFLAGS(sv) |= SVpbm_CASEFOLD)
  395. #define SvCASEFOLD_off(sv)    (SvFLAGS(sv) &= ~SVpbm_CASEFOLD)
  396.  
  397. #define SvVALID(sv)        (SvFLAGS(sv) & SVpbm_VALID)
  398. #define SvVALID_on(sv)        (SvFLAGS(sv) |= SVpbm_VALID)
  399. #define SvVALID_off(sv)        (SvFLAGS(sv) &= ~SVpbm_VALID)
  400.  
  401. #define SvMULTI(sv)        (SvFLAGS(sv) & SVpgv_MULTI)
  402. #define SvMULTI_on(sv)        (SvFLAGS(sv) |= SVpgv_MULTI)
  403. #define SvMULTI_off(sv)        (SvFLAGS(sv) &= ~SVpgv_MULTI)
  404.  
  405. #define SvRV(sv) ((XRV*)  SvANY(sv))->xrv_rv
  406. #define SvRVx(sv) SvRV(sv)
  407.  
  408. #define SvIVX(sv) ((XPVIV*)  SvANY(sv))->xiv_iv
  409. #define SvIVXx(sv) SvIVX(sv)
  410. #define SvNVX(sv)  ((XPVNV*)SvANY(sv))->xnv_nv
  411. #define SvNVXx(sv) SvNVX(sv)
  412. #define SvPVX(sv)  ((XPV*)  SvANY(sv))->xpv_pv
  413. #define SvPVXx(sv) SvPVX(sv)
  414. #define SvCUR(sv) ((XPV*)  SvANY(sv))->xpv_cur
  415. #define SvLEN(sv) ((XPV*)  SvANY(sv))->xpv_len
  416. #define SvLENx(sv) SvLEN(sv)
  417. #define SvEND(sv)(((XPV*)  SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
  418. #define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
  419. #define SvMAGIC(sv)    ((XPVMG*)  SvANY(sv))->xmg_magic
  420. #define SvSTASH(sv)    ((XPVMG*)  SvANY(sv))->xmg_stash
  421.  
  422. #define SvIV_set(sv, val) \
  423.     do { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
  424.         (((XPVIV*)  SvANY(sv))->xiv_iv = val); } while (0)
  425. #define SvNV_set(sv, val) \
  426.     do { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
  427.         (((XPVNV*)  SvANY(sv))->xnv_nv = val); } while (0)
  428. #define SvPV_set(sv, val) \
  429.     do { assert(SvTYPE(sv) >= SVt_PV); \
  430.         (((XPV*)  SvANY(sv))->xpv_pv = val); } while (0)
  431. #define SvCUR_set(sv, val) \
  432.     do { assert(SvTYPE(sv) >= SVt_PV); \
  433.         (((XPV*)  SvANY(sv))->xpv_cur = val); } while (0)
  434. #define SvLEN_set(sv, val) \
  435.     do { assert(SvTYPE(sv) >= SVt_PV); \
  436.         (((XPV*)  SvANY(sv))->xpv_len = val); } while (0)
  437. #define SvEND_set(sv, val) \
  438.     do { assert(SvTYPE(sv) >= SVt_PV); \
  439.         (((XPV*)  SvANY(sv))->xpv_cur = val - SvPVX(sv)); } while (0)
  440.  
  441. #define BmRARE(sv)    ((XPVBM*)  SvANY(sv))->xbm_rare
  442. #define BmUSEFUL(sv)    ((XPVBM*)  SvANY(sv))->xbm_useful
  443. #define BmPREVIOUS(sv)    ((XPVBM*)  SvANY(sv))->xbm_previous
  444.  
  445. #define FmLINES(sv)    ((XPVFM*)  SvANY(sv))->xfm_lines
  446.  
  447. #define LvTYPE(sv)    ((XPVLV*)  SvANY(sv))->xlv_type
  448. #define LvTARG(sv)    ((XPVLV*)  SvANY(sv))->xlv_targ
  449. #define LvTARGOFF(sv)    ((XPVLV*)  SvANY(sv))->xlv_targoff
  450. #define LvTARGLEN(sv)    ((XPVLV*)  SvANY(sv))->xlv_targlen
  451.  
  452. #define IoIFP(sv)    ((XPVIO*)  SvANY(sv))->xio_ifp
  453. #define IoOFP(sv)    ((XPVIO*)  SvANY(sv))->xio_ofp
  454. #define IoDIRP(sv)    ((XPVIO*)  SvANY(sv))->xio_dirp
  455. #define IoLINES(sv)    ((XPVIO*)  SvANY(sv))->xio_lines
  456. #define IoPAGE(sv)    ((XPVIO*)  SvANY(sv))->xio_page
  457. #define IoPAGE_LEN(sv)    ((XPVIO*)  SvANY(sv))->xio_page_len
  458. #define IoLINES_LEFT(sv)((XPVIO*)  SvANY(sv))->xio_lines_left
  459. #define IoTOP_NAME(sv)    ((XPVIO*)  SvANY(sv))->xio_top_name
  460. #define IoTOP_GV(sv)    ((XPVIO*)  SvANY(sv))->xio_top_gv
  461. #define IoFMT_NAME(sv)    ((XPVIO*)  SvANY(sv))->xio_fmt_name
  462. #define IoFMT_GV(sv)    ((XPVIO*)  SvANY(sv))->xio_fmt_gv
  463. #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
  464. #define IoBOTTOM_GV(sv)    ((XPVIO*)  SvANY(sv))->xio_bottom_gv
  465. #define IoSUBPROCESS(sv)((XPVIO*)  SvANY(sv))->xio_subprocess
  466. #define IoTYPE(sv)    ((XPVIO*)  SvANY(sv))->xio_type
  467. #define IoFLAGS(sv)    ((XPVIO*)  SvANY(sv))->xio_flags
  468.  
  469. #define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, Nullsv, 't', Nullch, 0)
  470.  
  471. #ifdef CRIPPLED_CC
  472.  
  473. IV SvIV _((SV* sv));
  474. double SvNV _((SV* sv));
  475. #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
  476. #define SvPV(sv, lp) sv_pvn(sv, &lp)
  477. char *sv_pvn _((SV *, STRLEN *));
  478. I32 SvTRUE _((SV *));
  479.  
  480. #define SvIVx(sv) SvIV(sv)
  481. #define SvNVx(sv) SvNV(sv)
  482. #define SvPVx(sv, lp) sv_pvn(sv, &lp)
  483. #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
  484. #define SvTRUEx(sv) SvTRUE(sv)
  485.  
  486. #else /* !CRIPPLED_CC */
  487.  
  488. #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
  489.  
  490. #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
  491.  
  492. #define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
  493.  
  494. #define SvPV_force(sv, lp) ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
  495.  
  496. #define SvTRUE(sv) (                        \
  497.     !sv                                \
  498.     ? 0                                \
  499.     :    SvPOK(sv)                        \
  500.     ?   ((Xpv = (XPV*)SvANY(sv)) &&                \
  501.          (*Xpv->xpv_pv > '0' ||                \
  502.           Xpv->xpv_cur > 1 ||                \
  503.           (Xpv->xpv_cur && *Xpv->xpv_pv != '0'))        \
  504.          ? 1                        \
  505.          : 0)                        \
  506.     :                            \
  507.         SvIOK(sv)                        \
  508.         ? SvIVX(sv) != 0                    \
  509.         :   SvNOK(sv)                    \
  510.         ? SvNVX(sv) != 0.0                \
  511.         : sv_2bool(sv) )
  512.  
  513. #define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
  514. #define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
  515. #define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
  516. #define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
  517.  
  518. #endif /* CRIPPLED_CC */
  519.  
  520. /* the following macro updates any magic values this sv is associated with */
  521.  
  522. #define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x)
  523.  
  524. #define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src)
  525.  
  526. #define SvPEEK(sv) sv_peek(sv)
  527.  
  528. #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
  529.  
  530. #ifndef DOSISH
  531. #  define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
  532. #  define Sv_Grow sv_grow
  533. #else
  534.     /* extra parentheses intentionally NOT placed around "len"! */
  535. #  define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
  536.         ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
  537. #  define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
  538. #endif /* DOSISH */
  539.